package com.stud.view;

import com.stud.exception.ValidationException;
import com.stud.rmi.Client;
import com.stud.service.ServiceWrapper;
import com.stud.util.JOptionPaneWrapper;

public class ClientController {

    private final ServiceWrapper service;
    private final ClientView view;
    private final JOptionPaneWrapper optionPaneWrapper;

    public ClientController(ServiceWrapper service, ClientView view, JOptionPaneWrapper optionPaneWrapper) {
        this.service = service;
        this.view = view;
        this.optionPaneWrapper = optionPaneWrapper;
    }

    public void saveClient() {
        service.saveClient(new Client(view.getFirstName(), view.getLastName()));
    }

    public void deleteClient() {
        try {
            service.deleteClient(new Client(view.getFirstName(), view.getLastName()));
        } catch (ValidationException e) {
            optionPaneWrapper.showMessageDialog(view.getClientFrame(), e.getMessage());
        }
    }
}
